package YuanFuDao2;

import java.util.Arrays;

/**
 * 手撕快排
 */
public class Main32 {
    public static void main(String[] args) {
        int[] nums = {2,6,4,9,1,34,13,6};
        quickSort(nums,0,nums.length-1);
        System.out.println(Arrays.toString(nums));
    }

    public static void quickSort(int[] nums,int start,int end){
        if(start > end) return;

        int left = start;
        int right = end;
        int base = nums[start];

        while(left < right){

            while(left < right && nums[right] >= base){
                right--;
            }
            nums[left] = nums[right];

            while(left <right && nums[left] <= base){
                left++;
            }
            nums[right] = nums[left];
        }

        nums[left] = base;

        quickSort(nums,start,left-1);
        quickSort(nums,left+1,end);


    }


}
